<form class="layui-form open-form" lay-filter="skuTableForm" id="skuTableForm">
  <div class="open-model">
    <div class="open-auto">
      <!-- 添加产品类型，产品SKU编号，产品名称查询功能 -->
      <div class="layui-form-item layui-row lay-query-box">
        <input name="id" type="hidden" />
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">物资类型：</label>
          <div class="layui-input-block">
            <div id="productTypeName" lay-filter="productTypeName"></div>
            <input id="productTypeId" name="productTypeId" type="hidden" />
            <!-- <select id="productTypeId" name="productTypeId" lay-filter="productTypeId"></select> -->
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label w-auto">物料编号：</label>
          <div class="layui-input-block">
            <input name="skuCode" class="layui-input" placeholder="请输入物料编号" />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">物料名称：</label>
          <div class="layui-input-block">
            <input name="skuName" class="layui-input" placeholder="请输入物料名称" />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">规格码：</label>
          <div class="layui-input-block">
            <input name="skuSpec" class="layui-input" placeholder="请输入规格码" />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <div class="layui-inline">
            <button class="layui-btn icon-btn color-green" lay-filter="queryBtn" lay-submit layui-form-keyDownSearch="true">查询</button>
            <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
          </div>
        </div>
      </div>
      <button class="layui-btn" id="isCheckFun" style="border-radius: 4px; margin-bottom: 10px">确认选择</button>
      <table id="orderFormTableTable"></table>
    </div>
    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
    </div>
  </div>
</form>

<script>
  layui.use(["layer", "form", "table", "admin", "upload", "tree", "laytpl"], async function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    const nowData = { ...parentData };

    let type = nowData.type ? nowData.type : "checkbox";

    let cacheList = nowData.cacheList;
/*
    let materialNatureList = nowData.materialNatureList ? nowData.materialNatureList : [2, 3, 7];
*/
    let materialNatureList = nowData.materialNatureList ? nowData.materialNatureList : "";

    admin.initDataSelectTree(
      true,
      "enterprise/product/admin/productType/getAllTreeData",
      { materialNatureList: materialNatureList },
      "productTypeName",
      null,
      "物料分类",
      "productTypeId"
    );

    table.render({
      elem: "#orderFormTableTable",

      url: config.base + `enterprise/product/admin/productDetailWMS/list`,
      where: { notInListIds: nowData.notInListIds,...nowData.where },
      page: true,
      cellMinWidth: 100,
      cols: [
        [
          { type: type, fixed: "left" },
          // , {field: 'skuCode', align: 'center', title: '产品图片'}
          { field: "skuCode", align: "center", title: "产品SKU编号" },
          { field: "skuName", align: "center", title: "产品名称" },
          { field: "skuSpec", align: "center", title: "规格码" },
          { field: "productTypeName", align: "center", title: "产品类型" },
          { field: "minPrice", align: "center", title: "产品单价" },
          { field: "baseUnitName", align: "center", title: "基础单位" },
          { field: "mainUnitName", align: "center", title: "主计价单位" },
          { field: "haveQuantity", align: "center", title: "库存数量" },
          {
            align: "center",
            title: "库存金额",
            templet: (d) => {
              return d.minPrice * d.haveQuantity;
            }
          }
        ]
      ]
    });
    form.on("submit(queryBtn)", function (data) {
      // 重载表格并传入查询参数
      table.reload("orderFormTableTable", {
        where: data.field,
        page: {
          curr: 1
        }
      });
      return false;
    });
    // 重置搜索
    form.on("submit(resets)", function (data) {
      table.reload(
        "orderFormTableTable",
        {
          where: admin.resetSearch(data.field),
          page: { curr: 1 }
        },
        "data"
      );
      return false;
    });
    $("#isCheckFun").click(() => {
      var checkStatus = table.checkStatus("orderFormTableTable");
      var data = checkStatus.data; // 选中的数据
      if (typeof parent.layui !== "undefined") {
        childData.list = data.map((v) => {
          v.productDetailId = v.id;
          delete v.id;
          return v;
        });
        layer.close(parentData.zindex); // 关闭指定的弹窗
      }
      return false;
    });
  });
</script>
<style>
  #skuTableForm .layui-input-block {
    margin-left: 130px;
  }
</style>
